function [data,titles] = read_flowjo_table(flow_path)

%read frequency in gates file from flowjo tables
%Array: [row,col,rep,gate]
fin = fopen(flow_path,'r');
line = 1;
rep = 0;
data = NaN(8,12,10,4); %assumes 96-well format, max 10 replicates
titles = '';
well_exp = '_([ABCDEFGH])(\d+)_';

while line>-1
    line = fgetl(fin);
%Q1-4: red, hetero, green, dead
    if any(line=='>')
        rep = rep+1;
        titles{rep} = line;
        titles{rep}(find(titles{rep}=='_'))=' ';
        fgetl(fin);
    end
    if strfind(line,'Specimen')
        tokens = regexp(line,well_exp,'tokens');
        row = uint8(find('ABCDEFGH'==tokens{1}{1}));
        col = uint8(str2num(tokens{1}{2}));
        freq = regexp(line,'\t','split');
        data(row,col,rep,:) = cellfun(@str2num,freq(2:end));
    end
end